﻿/**
 *	html/monitor/center/pem_center.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-07		create the file
 */

/**
 *	create subpanle panels for center panel
 *
 *	@panel_center		[in] the center panel object
 *
 *	return:
 *		void
 */
function _create_subpanel_for_center( panel_center )
{
    create_title_panel( panel_center, "show" );
    create_device_panel( panel_center, "hide" );
    create_scene_panel( panel_center, "show" );
    create_tunnel_panel( panel_center, "hide" );
    create_switch_panel( panel_center, "hide" );
    create_protocal_panel( panel_center, "hide" );
    create_alarm_panel( panel_center, "hide" );
    create_event_panel( panel_center, "hide" );
    create_system_panel( panel_center, "hide" );

    panel_center.show_subpanel 		= center_show_subpanel;
    panel_center.lasttree			= "tree_panel_monitor";
    panel_center.lastnode			= "root";

    panel_center.show_fun_array		= new Array();
    panel_center.show_fun_array["tree_panel_monitor"]	= show_subpanel_monitor;
    panel_center.show_fun_array["tree_panel_security"]	= show_subpanel_security;
    panel_center.show_fun_array["tree_panel_video"]		= show_subpanel_video;
    panel_center.show_fun_array["tree_panel_option"]	= show_subpanel_option;
    panel_center.show_fun_array["tree_panel_alarm"]		= show_subpanel_alarm;
    panel_center.show_fun_array["tree_panel_system"]	= show_subpanel_system;
}

/**
 *	show the monitor subpanel
 *
 *	@treeid			[in] the tree id
 *	@nodeid			[in] the tree node id
 *	@nodetext		[in] the tree node text
 */
function center_show_subpanel( treeid, nodeid, nodetext )
{
    // show title
    this.subpanel["panel_c_title"].removeAll();
    if ( nodetext === undefined )	nodetext = "";
    this.subpanel["panel_c_title"].add("<font size = 5><b>" + nodetext + "</b></font>");

    this.show_fun_array[this.lasttree]( this, this.lastnode, "hide" );
    if ( !(treeid === undefined || nodeid === undefined) )
    {
        this.show_fun_array[treeid]( this, nodeid, "show" );
        this.lasttree = treeid;
        this.lastnode = nodeid;
    }
}

function show_subpanel_monitor( obj, nodeid, showflag )
{
    var	panel_c_scene		= obj.subpanel["panel_c_scene"];

    if ( "show" === showflag )
        panel_c_scene.show();
    else
        panel_c_scene.hide();

    panel_c_scene.show_setting_button( "hide" );

    switch( nodeid )
    {
    case "root":
        panel_c_scene.show_all_device( showflag ); break;
    case "themometor":
    case "hygrometer":
    case "anemograph":
    case "sf6":
    case "light":
    case "smoke":
    case "guard":
        panel_c_scene.show_specific_device( nodeid, showflag ); break;
    }
}

function show_subpanel_security( obj, nodeid, showflag )
{
    var	panel_c_scene		= obj.subpanel["panel_c_scene"];

    panel_c_scene.show_setting_button( "hide" );

    if ( "show" === showflag )
        panel_c_scene.show();
    else
        panel_c_scene.hide();

    switch( nodeid )
    {
    case "root":
        panel_c_scene.show_all_device( showflag ); break;
    case "infrared":
    case "dbinfrared":
    case "e_fence":
    case "wetness_probe":
        panel_c_scene.show_specific_device( nodeid, showflag ); break;
    }
}

function show_subpanel_video( obj, nodeid, showflag )
{
    if ( "show" === showflag )
    {
        //obj.subpanel["panel_c_vedio"].show();
        //obj.subpanel["panel_c_scene"].show_subpanel( nodeid );
    }
}

function show_subpanel_option( obj, nodeid, showflag )
{
    var draggable 		= has_administrator_right();
    var	panel_c_scene	= obj.subpanel["panel_c_scene"];

    if ( "show" === showflag )
    {
        switch( nodeid )
        {
        case "root":
        case "scene":
            panel_c_scene.show();
            panel_c_scene.show_all_device( "hide" );
            panel_c_scene.show_setting_button( "show" );
            break;
        case "tunnel":
            obj.subpanel["panel_c_tunnel"].show(); break;
        case "protocal":
            obj.subpanel["panel_c_protocal"].show(); break;
        case "device":
            obj.subpanel["panel_c_device"].show();
            panel_c_scene.show();
            panel_c_scene.show_all_device( showflag, draggable );
            panel_c_scene.show_setting_button( "hide" );
            break;
        case "switch":
            obj.subpanel["panel_c_switch"].show(); break;
        }
    }
    else
    {
        switch( nodeid )
        {
        case "root":
        case "scene":
            panel_c_scene.hide();
            break;
        case "tunnel":
            obj.subpanel["panel_c_tunnel"].hide(); break;
        case "protocal":
            obj.subpanel["panel_c_protocal"].hide(); break;
        case "device":
            obj.subpanel["panel_c_device"].hide();
            panel_c_scene.hide();
            panel_c_scene.show_all_device( showflag, draggable );
            break;
        case "switch":
            obj.subpanel["panel_c_switch"].hide(); break;
        }
    }
}

function show_subpanel_alarm( obj, nodeid, showflag )
{
    if ( "show" === showflag )
    {
        switch( nodeid )
        {
        case "threshold":
            obj.subpanel["panel_c_alarm"].show(); break;
        case "event":
            obj.subpanel["panel_c_event"].show(); break;
        }
    }
    else
    {
        switch( nodeid )
        {
        case "threshold":
            obj.subpanel["panel_c_alarm"].hide(); break;
        case "event":
            obj.subpanel["panel_c_event"].hide(); break;
        }
    }
}

function show_subpanel_system( obj, nodeid, showflag )
{
    var	panel_c_system	= obj.subpanel["panel_c_system"];

    if ( "show" === showflag )
        panel_c_system.show();
    else
        panel_c_system.hide();
}
